/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.webrx;

import java.util.HashSet;
import java.util.List;

/**
 * <p>Project: javaseapp - Set1
 * <p>Powered by webrx On 2021-08-09 17:38:27
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Set1 {
    public static void main(String[] args) {
        //Set 没有索引号，是无序，对象不能重复。
        //Set是接口 HashSet是Set接口的实现类
        //Set<String> set = new HashSet<String>();
        var set = new HashSet<String>();
        set.add("java");
        set.add("java");
        set.add("java");
        //set.clear();
        System.out.println(set.contains("java"));
        set.remove("java");
        set.clear();
        set.addAll(List.of("java", "javascript", "java", "c", "go", "php"));
        System.out.println(set.size());

        System.out.println(set);
        //将set 对象转换为Stream 流对象有直接排序功能，
        set.stream().sorted().forEach(System.out::print);
        System.out.println(set);

        //遍历输出 方法一
        for (String s : set) {
            System.out.println(s);
        }

        //方法二
        set.forEach(System.out::print);


    }
}
